<?=$this->header(true)?>


    <?=$this->menu("guides")?>


    <h1><?=$this->message("nav.guides")?></h1>


    <? /* Breadcrums route */ ?>
    <?=$this->route(
        array(
            array(
                "name"=>$this->message("nav.guides"),
                "href"=>"guide/list"
            ),
            array(
                "name"=>$this->languageRoute(
                            $this->message("label.item", _Guide::BUNDLE),       // Item name
                            $this->guideForm->getGuideI18n()->getDefaultName(
                                $this->param(_Core::DEFAULT_LANGUAGE)),         // Default language item name
                            $this->guideForm->getGuideI18n()->getGuideI18nId(), // Id
                            $this->guideForm->getGuideI18n()->getLanguage())    // Language
            )
        )
    )?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _Guide::BUNDLE)?>


    <form id="<?=get_class($this->guideForm)?>" action="guide/save" method="post" enctype="multipart/form-data">

        <div>
            <input type="hidden"
                   name="guideI18n->guideI18nId"
                   value="<?=$this->guideForm->getGuideI18n()->getGuideI18nId()?>" />
            <input type="hidden"
                   name="guideI18n->guideId"
                   value="<?=$this->guideForm->getGuideI18n()->getGuideId()?>" />
            <input type="hidden"
                   name="guideI18n->languageCode"
                   value="<?=$this->guideForm->getGuideI18n()->getLanguageCode()?>" />

        </div>

        <fieldset>

            <legend><?=$this->message("label.required")?></legend>

            <table cellspacing="0" cellpadding="0" class="form">

            <? /* Only show country with default language guides */ ?>
            <? if($this->guideForm->getGuideI18n()->getLanguageCode() == $this->param(_Core::DEFAULT_LANGUAGE)): ?>

                <tr class="ctrl<?=$this->error("guideI18n->guide->countryCode")?>">
                    <th><label for="guideI18n_guide_countryCode"><?=$this->message("prompt.country", _Guide::BUNDLE)?></label></th>
                    <th class="required"><em>*</em></th>
                    <td>
                        <select name="guideI18n->guide->countryCode" id="guideI18n_guide_countryCode" class="icon-menu">
                            <option value="">--</option>
                            <? foreach($this->countries() as $country): ?>
                                <option
                                    value="<?=$country->getCode()?>"
                                    style="background-image:url(static.php?file=<?=$this->image("cms/core/view/gfx/flag/".$country->getCode().".png")?>);"
                                    <?=$country->getCode() == $this->guideForm->getGuideI18n()->getGuide()->getCountryCode() ? " selected=\"selected\"" : ""?>>
                                        <?=$country->getPrintableName()?>
                                </option>
                            <? endforeach; ?>
                        </select>
                    </td>
                </tr>

            <? endif; ?>

            <tr class="ctrl<?=$this->error("guideI18n->description1")?>">
                <th><label for="guideI18n_description1"><?=$this->message("prompt.info", _Guide::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <textarea name="guideI18n->description1"
                              id="guideI18n_description1"
                              rows="16" cols="70"
                              mce_editable="true"><?=!is_null($this->guideForm->getGuideI18n()->getDescription1()) ?
                                $this->guideForm->getGuideI18n()->getDescription1()->getContents() : ""?></textarea>
                    <p class="hint"><?=$this->message("note.image", _Core::BUNDLE, null, null, false)?></p>
                </td>
            </tr>
            <tr class="ctrl<?=$this->error("guideI18n->description2")?>">
                <th><label for="guideI18n_description2"><?=$this->message("prompt.un", _Guide::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <textarea name="guideI18n->description2"
                              id="guideI18n_description2"
                              rows="16" cols="70"
                              mce_editable="true"><?=!is_null($this->guideForm->getGuideI18n()->getDescription2()) ?
                                $this->guideForm->getGuideI18n()->getDescription2()->getContents() : ""?></textarea>
                    <p class="hint"><?=$this->message("note.image", _Core::BUNDLE, null, null, false)?></p>
                </td>
            </tr>
            </table>

        </fieldset>

        <fieldset>

            <legend><?=$this->message("label.optional")?></legend>

            <table cellspacing="0" cellpadding="0" class="form">

            <tr class="ctrl<?=$this->error("guideI18n->intro")?>">
                <th><label for="guideI18n_intro"><?=$this->message("prompt.intro", _Guide::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <textarea name="guideI18n->intro"
                              id="guideI18n_intro"
                              rows="7" cols="80"><?=!is_null($this->guideForm->getGuideI18n()->getIntro()) ?
                                $this->guideForm->getGuideI18n()->getIntro()->getContents() : ""?></textarea>
                    <p class="hint"><?=$this->message("note.intro", _Core::BUNDLE)?></p>
                </td>
            </tr>

            <? /* Only show url with default language guides */ ?>
            <? if($this->guideForm->getGuideI18n()->getLanguageCode() == $this->param(_Core::DEFAULT_LANGUAGE)): ?>

                <tr class="ctrl<?=$this->error("guideI18n->guide->url")?>">
                    <th><label for="guideI18n_guide_url"><?=$this->message("prompt.url", _Guide::BUNDLE)?></label></th>
                    <th class="required"><em></em></th>
                    <td>
                        <input name="guideI18n->guide->url"
                               id="guideI18n_guide_url"
                               value="<?=$this->guideForm->getGuideI18n()->getGuide()->getUrl()?>"
                               maxlength="255"
                               type="text"
                               class="textInput" />
                        <p class="hint"><?=$this->message("note.url", _Core::BUNDLE)?></p>
                    </td>
                </tr>
                <tr class="ctrl<?=$this->error("formImage")?>">
                    <th><label for="formImage"><?=$this->message("label.image", _Core::BUNDLE)?></label></th>
                    <th class="required"><em>&nbsp;</em></th>
                    <td>
                        <? if(!is_null($this->guideForm->getGuideI18n()->getGuide()) &&
                            $this->guideForm->getGuideI18n()->getGuide()->getImageId() > 0 &&
                            !is_null($this->guideForm->getGuideI18n()->getGuide()->getImageRelatedByImageId())) { ?>

                            <input type="hidden"
                                   name="guideI18n->guide->imageRelatedByImageId->imageId"
                                   value="<?=$this->guideForm->getGuideI18n()->getGuide()->getImageId()?>" />
                            <input type="hidden"
                                   name="guideI18n->guide->imageRelatedByThumbnailId->imageId"
                                   value="<?=$this->guideForm->getGuideI18n()->getGuide()->getThumbnailId()?>" />

                            <input type="hidden"
                                   name="guideI18n->guide->imageRelatedByImageId->binaryFileId"
                                   value="<?=$this->guideForm->getGuideI18n()->getGuide()->getImageRelatedByImageId()->getBinaryFileId()?>" />
                            <input type="hidden"
                                   name="guideI18n->guide->imageRelatedByThumbnailId->binaryFileId"
                                   value="<?=$this->guideForm->getGuideI18n()->getGuide()->getImageRelatedByThumbnailId()->getBinaryFileId()?>" />

                            <img src="image?id=<?=$this->guideForm->getGuideI18n()->getGuide()->getImageId()?>"
                                 width="<?=$this->guideForm->getGuideI18n()->getGuide()->getImageRelatedByImageId()->getWidth()?>"
                                 height="<?=$this->guideForm->getGuideI18n()->getGuide()->getImageRelatedByImageId()->getHeight()?>" alt="" />

                            <input type="checkbox" name="deleteImage" value="true" id="deleteImage" /> <label for="deleteImage"><?=$this->message("label.image.delete", _Core::BUNDLE)?></label>

                            <br /><br />

                        <? } ?>

                        <input type="file" name="formImage" />

                        <p class="hint"><?=$this->message("note.image.resize", _Core::BUNDLE)?> <?=$this->imageProps($this->param(_Core::SETTING_LIST))->getImageWidth()?>x<?=$this->imageProps($this->param(_CORE::SETTING_LIST))->getImageHeight()?>.</p>

                    </td>
                </tr>

            <? endif; ?>
            </table>

        </fieldset>

        <div class="buttons">

            <input type="button"
                   onclick="to('guide/list')"
                   value="<?=$this->message("button.cancel", _Core::BUNDLE)?>"
                   class="button" />
            <input type="submit"
                   value="<?=$this->message("button.submit", _Core::BUNDLE)?>"
                   class="button" />

        </div>

    </form>

<?=$this->footer()?>